package com.example.zk.configure;

import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.web.bind.annotation.RestController;


import javax.sql.DataSource;

public class DataConfigure {
    private static JdbcTemplate jdbcTemplate= new JdbcTemplate( dataSource());;
    private DataConfigure(){ }

    /**
     * 获取连接
     * @return
     */
    public  static  JdbcTemplate getJdbcTemplate(){
        return jdbcTemplate;
    }

    /**
     * 设置数据源
     * @param dataSource
     * @return
     */
    public  static  JdbcTemplate setDataConfigure(DriverManagerDataSource dataSource){
        jdbcTemplate=new JdbcTemplate(dataSource);;
        return jdbcTemplate;
    }


    //@Bean(name = "dataSource")
    public static DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC");
        dataSource.setUsername("root");
        dataSource.setPassword("root");
        return dataSource;


    }


}
